Runtime (Java SE 21 & JDK 21) 您所在的位置:网站首页 exec java -jar Runtime (Java SE 21 & JDK 21)

Runtime (Java SE 21 & JDK 21)

2024-04-13 21:01| 来源: 网络整理| 查看: 265

Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method.

An application cannot create its own instance of this class.

Shutdown Sequence

The Java Virtual Machine initiates the shutdown sequence in response to one of several events:

when the number of live non-daemon threads drops to zero for the first time (see note below on the JNI Invocation API); when the Runtime.exit or System.exit method is called for the first time; or when some external event occurs, such as an interrupt or a signal is received from the operating system.

At the beginning of the shutdown sequence, the registered shutdown hooks are started in some unspecified order. They run concurrently with any daemon or non-daemon threads that were alive at the beginning of the shutdown sequence.

After the shutdown sequence has begun, registration and de-registration of shutdown hooks with addShutdownHook and removeShutdownHook is prohibited. However, creating and starting new threads is permitted. New threads run concurrently with the registered shutdown hooks and with any daemon or non-daemon threads that are already running.

The shutdown sequence finishes when all shutdown hooks have terminated. At this point, the Java Virtual Machine terminates as described below.

It is possible that one or more shutdown hooks do not terminate, for example, because of an infinite loop. In this case, the shutdown sequence will never finish. Other threads and shutdown hooks continue to run and can terminate the JVM via the halt method.

Prior to the beginning of the shutdown sequence, it is possible for a program to start a shutdown hook by calling its start method explicitly. If this occurs, the behavior of the shutdown sequence is unspecified.

Java Virtual Machine Termination

The JVM terminates when the shutdown sequence finishes or when halt is called. In contrast to exit, the halt method does not initiate the shutdown sequence.

When the JVM terminates, all threads are immediately prevented from executing any further Java code. This includes shutdown hooks as well as daemon and non-daemon threads. This means, for example, that:

threads' current methods do not complete normally or abruptly; finally clauses are not executed; uncaught exception handlers are not run; and resources opened with try-with-resources are not closed;


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有